package com.macrounion.atv.controller.api;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macrounion.atv.processor.UserProcessor;
import com.macrounion.atv.service.entity.User;
import com.macrounion.base.controller.api.BaseApi;
import com.macrounion.base.service.dto.BaseRespDto;
import com.macrounion.base.service.dto.LoginReqDto;
import com.macrounion.base.service.utils.SessionHandler;

@Controller
@RequestMapping("/api/login")
public class LoginApiController extends BaseApi<User>{

	@Autowired
	protected HttpServletRequest request;
	@Autowired
	private UserProcessor userProcessor;
	
	@RequestMapping(value="/check",method=RequestMethod.POST)
	public @ResponseBody BaseRespDto<String> login(@RequestBody LoginReqDto loginDto){
		User userResp=userProcessor.checkLogin(loginDto.getAccount(), loginDto.getPwd());
		SessionHandler.setContext(userResp);
		super.setContextUser(userResp);
		return new BaseRespDto<>("success");
	}
}
